var param_platform_code = $.url().param('platform_code');
var param_type_code = $.url().param('type_code');
var param_league_code = $.url().param('league_code');
var param_left_code = $.url().param('left_code');
var param_right_code = $.url().param('right_code');
var param_date = $.url().param('date');

getPlayInfo(param_platform_code, param_type_code, param_league_code, param_left_code, param_right_code, param_date);

function getPlayInfo(platform_code, type_code, league_code, left_code, right_code, date) {
    $("#play_loading_zone").show();
    $("#play_data_zone").hide();
    $("#play_error_zone").hide();
    var token = getCookie('csrftoken');
    $.ajax({
        // url: '/football/get_play_info/',
        url: 'http://8.134.215.241:9080/jyb/core/plat/acquireplatplays',
        type: 'POST',
        headers:{'X-CSRFToken': token, "Content-Type": "application/json"},
        data: JSON.stringify({'baseDate': date, 'platCode': platform_code, 'typeCode': type_code, 'leaCode': league_code, 'teamCodeLeft': left_code, 'teamCodeRight': right_code}),
        success: function(data) {
            let jsonData = data['result']['platPlayVoList'];
            console.log(jsonData);
            let listHtml = "";
            listHtml = listHtml + '<div class="self_common_zone">';
            jsonData.forEach((item, index) => {
                let play_code = item['playCode'];
                let play_name = item['playName'];
                listHtml = listHtml + '<div data-date="' + date + '" data-left="' + left_code + '" data-right="' + right_code + '" data-platform="' + platform_code + '" data-type="' + type_code + '" data-league="' + league_code + '" data-play="' + play_code + '" onclick="goToRatePage(this)" class="self_common_item self_common_item_size_normal self_letter_spacing_2">';
                listHtml = listHtml + '<span>';
                listHtml = listHtml + play_name;
                listHtml = listHtml + '</span>';
                listHtml = listHtml + '</div>';
            });
            listHtml = listHtml + '</div>';
            $("#play_data_zone").html(listHtml);
            $("#play_loading_zone").hide();
            $("#play_error_zone").hide();
            $("#play_data_zone").show();
        },
        error: function() {
            $("#play_loading_zone").hide();
            $("#play_data_zone").hide();
            $("#play_error_zone").show();
        }
    });
}

function goToRatePage(element) {
    const platform_code = element.dataset.platform;
    const type_code = element.dataset.type;
    const league_code = element.dataset.league;
    const left_code = element.dataset.left;
    const right_code = element.dataset.right;
    const play_code = element.dataset.play;
    const date = element.dataset.date;
    if (play_code === "01") {
    }
    goToOtherPage('./rate_common.html?platform_code=' + platform_code + '&type_code=' + type_code + '&league_code=' + league_code + '&left_code=' + left_code + '&right_code=' + right_code + '&play_code=' + play_code + '&date=' + date );
}

function navigateToPlatformPage() {
    goToOtherPage('./platform.html?date=' + param_date );
}

function navigateToTypePage() {
    goToOtherPage('./type.html?platform_code=' + param_platform_code + '&date=' + param_date);
}

function navigateToLeaguePage() {
    goToOtherPage('./league.html?platform_code=' + param_platform_code + '&type_code=' + param_type_code + '&date=' + param_date);
}

function navigateToMatchPage() {
    goToOtherPage('./match.html?platform_code=' + param_platform_code + '&type_code=' + param_type_code + '&league_code=' + param_league_code + '&date=' + param_date);
}